﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProgNetComponents.Data.SqlCe;

namespace BuildHelper.Init.Defaults
{
    public class STP_APPS
    {
        public static void CreateDefault()
        {
            Setup.Apps.ProjektyDataSet ds = new Setup.Apps.ProjektyDataSet();
            using (SqlCeDataManager m = new SqlCeDataManager())
            {
                m.AddTableDef(ds.STP_APPS);
                m.FillDataSet(ds);

                AddApp(ds.STP_APPS, "GCM", "", "");
                AddApp(ds.STP_APPS, "GENESDK", "SDK", "", "");
                AddApp(ds.STP_APPS, "MOL", "M", "SoftMolecular");
                AddApp(ds.STP_APPS, "BIO", "B", "SoftBioChemistry");
                AddApp(ds.STP_APPS, "CTG", "C", "SoftCytogenetics");
                AddApp(ds.STP_APPS, "DXP", "P", "Soft Pathology Dx");
                AddApp(ds.STP_APPS, "FLW", "F", "SoftFlow Cytometry");
                AddApp(ds.STP_APPS, "ACC", "G", "SoftPre-Analytical");
                AddApp(ds.STP_APPS, "HLA", "H", "SoftHLA");
                AddApp(ds.STP_APPS, "GLAB", "L", "SoftGLab");
                AddApp(ds.STP_APPS, "IDX");
                m.UpdateDataSet(ds);
            }
        }
        
        public static void AddApp(Setup.Apps.ProjektyDataSet.STP_APPSDataTable table, string STP_APP_KOD)
        {
            AddApp(table, STP_APP_KOD, STP_APP_KOD, STP_APP_KOD, "", "", true, false);
        }
        public static void AddApp(Setup.Apps.ProjektyDataSet.STP_APPSDataTable table, string STP_APP_KOD, string STP_APP_GENE_LETTER, string STP_APP_GENE_NAZWA, bool STP_APP_IS_JAVA = true, bool STP_APP_IS_GUI = true)
        {
            AddApp(table, STP_APP_KOD, STP_APP_KOD, STP_APP_KOD, STP_APP_GENE_LETTER, STP_APP_GENE_NAZWA, STP_APP_IS_JAVA, STP_APP_IS_GUI);
        }
        public static void AddApp(Setup.Apps.ProjektyDataSet.STP_APPSDataTable table, string STP_APP_KOD, string STP_APP_JAVA_NAME, string STP_APP_GENE_LETTER, string STP_APP_GENE_NAZWA, bool STP_APP_IS_JAVA = true, bool STP_APP_IS_GUI = true)
        {
            AddApp(table, STP_APP_KOD, STP_APP_KOD, STP_APP_JAVA_NAME, STP_APP_GENE_LETTER, STP_APP_GENE_NAZWA, STP_APP_IS_JAVA, STP_APP_IS_GUI);
        }
        public static void AddApp(Setup.Apps.ProjektyDataSet.STP_APPSDataTable table, string STP_APP_KOD, string STP_APP_NAZWA, string STP_APP_JAVA_NAME, string STP_APP_GENE_LETTER, string STP_APP_GENE_NAZWA, bool STP_APP_IS_JAVA = true, bool STP_APP_IS_GUI = true)
        {
            bool commit = false;
            SqlCeDataManager m = null;
            try
            {
                if (table == null)
                {
                    m = new SqlCeDataManager();
                    m.AutoCommit = true;
                    m.AutoLogExceptions = true;
                    Setup.Apps.ProjektyDataSet ds = new Setup.Apps.ProjektyDataSet();
                    commit = true;
                    table = ds.STP_APPS;
                    m.AddTableDef(ds.STP_APPS);
                    m.FillTable(ds.STP_APPS);
                    ds.AcceptChanges();
                }
                if (table.SelectFirstRow("STP_APP_KOD = " + STP_APP_KOD.EscapeSql()) == null)
                    table.AddSTP_APPSRow(STP_APP_KOD, STP_APP_NAZWA, STP_APP_JAVA_NAME, STP_APP_GENE_LETTER, STP_APP_GENE_NAZWA, STP_APP_IS_JAVA, STP_APP_IS_GUI);

                if (commit)
                    m.UpdateTable(table);
            }
            finally
            {
                if (m != null)
                    m.Dispose();
            }
        }
    }
}
